// $URL: http://mingw-lib.googlecode.com/svn/trunk/working/avcodec_to_widget_9/input/t_box_input_file.cpp $
// $Rev: 312 $
// $Author: akio.miyoshi $
// $Date:: 2010-07-31 03:51:36 +0000#$

#include "t_box_input_file.h"

T_Box_Input_File::T_Box_Input_File(QString a_filename)
    : m_buffer(new quint8[c_buffer_size])
    , m_file(a_filename)
{
    if(!m_file.open(QIODevice::ReadOnly))
    {
        qDebug() << "file open failed";
    }
}

T_Box_Input_File::~T_Box_Input_File()
{
    if(m_file.isOpen()) m_file.close();
    delete [] m_buffer;
}

bool T_Box_Input_File::isValid()
{
    if(!m_file.isOpen()) return false;
    return true;
}

void T_Box_Input_File::close()
{
    if(!m_file.isOpen()) return;
    m_file.close();
}

int T_Box_Input_File::getIOBufferSize()
{
    return c_buffer_size;
}

qint64 T_Box_Input_File::size()
{
    if(!m_file.isOpen()) return -1;
    return m_file.size();
}

qint64 T_Box_Input_File::pos()
{
    if(!m_file.isOpen()) return -1;
    return m_file.pos();
}

bool T_Box_Input_File::seek(qint64 offset)
{
    if(!m_file.isOpen()) return false;
    return m_file.seek(offset);
}

QByteArray T_Box_Input_File::wait_read(qint64 a_max_size)
{
    if(!m_file.isOpen()) return QByteArray();
    return m_file.read(a_max_size);
}
